#define _CRT_SECURE_NO_WARNINGS 1

//void test()
//{
//	static int i = 0;
//}
//
//int main()
//{
//	test();
//	i++;
//	return 0;
//}

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
typedef struct ListNode LN;
struct ListNode* removeElements(struct ListNode* head, int val)
{
    LN* ret = (LN*)malloc(sizeof(LN));
    if (ret == NULL)
    {
        exit(1);
    }
    LN* prev = ret;
    prev->next = head;
    LN* pcur = head;
    while (pcur)
    {
        if (pcur->val == val)
        {
            prev->next = pcur->next;
            free(pcur);
            pcur = prev->next;
        }
        else
        {
            prev = pcur;
            pcur = prev->next;
        }
    }
    LN* ret1 = ret->next;
    free(ret);
    ret = NULL;

    return ret1;
}
